package com.neuedu.autosale.sys.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.neuedu.autosale.entity.Pager;
import com.neuedu.autosale.entity.Result;
import com.neuedu.autosale.sys.entity.Provider;
import com.neuedu.autosale.sys.entity.Type;
import com.neuedu.autosale.sys.service.TypeService;

@Controller
public class TypeController {
	
	@Autowired
	private TypeService typeService;
	
	@RequestMapping("typr/index")
	public String typeIndex() {
		return "car/typelist";
	}
	
	@RequestMapping("typr/findall")
	@ResponseBody
	public List<Type> typrFindall(){
		return typeService.findAll();
	}
	
	@RequestMapping("typr/list")
	@ResponseBody
	public Pager<Type> typelist(@RequestParam(value = "page", defaultValue = "1") Integer page,
			@RequestParam(value = "rows", defaultValue = "10") Integer rows) {
		Pager<Type> pager = new Pager<>(page, rows);
		List<Type> typelist = typeService.findListByPager(pager);
		int total = typeService.findTotalByPager(pager);
		pager.setRows(typelist);
		pager.setTotal(total);
		return pager;
	}
	
	@RequestMapping("typr/add")
	@ResponseBody
	public Result doAdd(Type type) {
		Result result = typeService.add(type);
		return result;
	}
	
	@RequestMapping("typr/edit")
	@ResponseBody
	public Result doEdit(Type type) {
		Result result = typeService.edit(type);
		return result;
	}
	
	@RequestMapping("typr/delete")
	@ResponseBody
	public Result doDelete(Integer typeId) {
		List<Type> list = new ArrayList<Type>();
		list.add(new Type(typeId));
		Result result = typeService.deleteByIds(list);
		return result;
	}
	
}
